<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Resolver  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a title="Resolver  Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="index.html">Resolver Docs</a> (36% documented)</p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="index.html">Resolver Reference</a>
        <img id="carat" src="img/carat.png" />
        Resolver  Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/Resolver.html">Resolver</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/Resolver/Name.html">– Name</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/Resolver/Args.html">– Args</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverOptions.html">ResolverOptions</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverRegistration.html">ResolverRegistration</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverRegistrationArgumentsN.html">ResolverRegistrationArgumentsN</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverRegistrationOnly.html">ResolverRegistrationOnly</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverRegistrationResolver.html">ResolverRegistrationResolver</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverScope.html">ResolverScope</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverScopeCache.html">ResolverScopeCache</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverScopeGraph.html">ResolverScopeGraph</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverScopeShare.html">ResolverScopeShare</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ResolverScopeUnique.html">ResolverScopeUnique</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Extensions/UIViewController.html">UIViewController</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Protocols/ResolverRegistering.html">ResolverRegistering</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/ResolverScopeType.html">ResolverScopeType</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Resolving.html">Resolving</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/StoryboardResolving.html">StoryboardResolving</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Structs.html">Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Structs/Injected.html">Injected</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/InjectedObject.html">InjectedObject</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/LazyInjected.html">LazyInjected</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/OptionalInjected.html">OptionalInjected</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/WeakLazyInjected.html">WeakLazyInjected</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Typealiases.html">Type Aliases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:8Resolver0A7Factorya">ResolverFactory</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:8Resolver0A17FactoryArgumentsNa">ResolverFactoryArgumentsN</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:8Resolver0A14FactoryMutatora">ResolverFactoryMutator</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:8Resolver0A24FactoryMutatorArgumentsNa">ResolverFactoryMutatorArgumentsN</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:8Resolver0a7FactoryA0a">ResolverFactoryResolver</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            
            <h1 id='resolver-img-src-https-user-images-githubusercontent-com-709283-32858974-cce8282a-ca12-11e7-944b-c8046156290b-png-alt-icon' class='heading'>Resolver <img src="https://user-images.githubusercontent.com/709283/32858974-cce8282a-ca12-11e7-944b-c8046156290b.png" alt="icon"></h1>

<p>An ultralight Dependency Injection / Service Locator framework for Swift 5.2 on iOS.</p>
<h2 id='introduction' class='heading'>Introduction</h2>

<p>Dependency Injection frameworks support the <a href="https://en.wikipedia.org/wiki/Inversion_of_control">Inversion of Control</a> design pattern. Technical definitions aside, dependency injection pretty much boils down to:</p>

<p>| <strong>Giving an object the things it needs to do its job.</strong></p>

<p>That&rsquo;s it. Dependency injection allows us to write code that&rsquo;s loosely coupled, and as such, easier to reuse, to mock, and  to test.</p>

<p>For more, see: <a href="./Documentation/Introduction.md">A Gentle Introduction to Dependency Injection.</a></p>
<h2 id='resolver-1-3-changes' class='heading'>Resolver 1.3 Changes</h2>

<p>Resolver 1.3 adds Name spaces to Resolver. Registering names allows for better autocompletion and makes your code safer by reducing potential runtime evaluation errors.</p>
<pre class="highlight swift"><code><span class="nf">register</span><span class="p">(</span><span class="nv">name</span><span class="p">:</span> <span class="o">.</span><span class="n">fred</span><span class="p">)</span> <span class="p">{</span> <span class="kt">XYZServiceFred</span><span class="p">()</span> <span class="k">as</span> <span class="kt">XYZServiceProtocol</span> <span class="p">}</span>
<span class="nf">register</span><span class="p">(</span><span class="nv">name</span><span class="p">:</span> <span class="o">.</span><span class="n">barney</span><span class="p">)</span> <span class="p">{</span> <span class="kt">XYZServiceBarney</span><span class="p">()</span> <span class="k">as</span> <span class="kt">XYZServiceProtocol</span> <span class="p">}</span>

<span class="k">let</span> <span class="nv">service</span><span class="p">:</span> <span class="kt">XYZServiceProtocol</span> <span class="o">=</span> <span class="nf">resolve</span><span class="p">(</span><span class="nv">name</span><span class="p">:</span> <span class="o">.</span><span class="n">fred</span><span class="p">)</span>
</code></pre>

<p>For more see: <a href="./Documentation/Names.md">Named Instances</a></p>
<h2 id='resolver-1-2-changes' class='heading'>Resolver 1.2 Changes</h2>

<p>Note that Resolver 1.2 changed how arguments are passed to the registration factory order to provide better support for passing and handling both single and multiple arguments. This is, unfortunately, a breaking change from Resolver 1.1.X, but as the end result is much cleaner code I think it&rsquo;s worth it. If you&rsquo;re <em>not</em> using arguments then you should see no issues whatsoever.</p>

<p>See: <a href="./Documentation/Arguments.md#multiple">Passing and Handling Multiple Arguments</a></p>
<h2 id='dependency-injection-strategies' class='heading'>Dependency Injection Strategies</h2>

<p>There are six classic dependency injection strategies:</p>

<ol>
<li><a href="./Documentation/Injection.md#interface">Interface Injection</a></li>
<li><a href="./Documentation/Injection.md#property">Property Injection</a></li>
<li><a href="./Documentation/Injection.md#constructor">Constructor Injection</a></li>
<li><a href="./Documentation/Injection.md#method">Method Injection</a></li>
<li><a href="./Documentation/Injection.md#locator">Service Locator</a></li>
<li><a href="./Documentation/Injection.md#annotation">Annotation</a> (NEW)</li>
</ol>

<p>Resolver supports them all. Follow the links for a brief description, examples, and the pros and cons of each.</p>
<h2 id='property-wrappers' class='heading'>Property Wrappers</h2>

<p>Resolver now supports resolving services using the new property wrapper syntax in Swift 5.1.</p>
<pre class="highlight swift"><code><span class="kd">class</span> <span class="kt">BasicInjectedViewController</span><span class="p">:</span> <span class="kt">UIViewController</span> <span class="p">{</span>
    <span class="kd">@Injected</span> <span class="k">var</span> <span class="nv">service</span><span class="p">:</span> <span class="kt">XYZService</span>
    <span class="kd">@LazyInjected</span> <span class="k">var</span> <span class="nv">service2</span><span class="p">:</span> <span class="kt">XYZLazyService</span>
    <span class="kd">@WeakLazyInjected</span> <span class="k">var</span> <span class="nv">service3</span><span class="p">:</span> <span class="kt">XYZAnotherLazyService</span><span class="p">?</span>
<span class="p">}</span>
</code></pre>

<p>Just add the Injected keyword and your dependencies will be resolved automatically. See the <a href="./Documentation/Annotation.md">Annotation</a> documentation for more on this and other strategies.</p>
<h2 id='features' class='heading'>Features</h2>

<p>Resolver is implemented in just over 700 lines of actual code in a single file, but it packs a ton of features into those 700 lines.</p>

<ul>
<li><a href="./Documentation/Types.md">Automatic Type Inference</a></li>
<li><a href="./Documentation/Scopes.md">Scopes: Application, Cached, Graph, Shared, and Unique</a></li>
<li><a href="./Documentation/Protocols.md">Protocols</a></li>
<li><a href="./Documentation/Optionals.md">Optionals</a></li>
<li><a href="./Documentation/Names.md">Named Instances</a> (Resolver 1.3 now supports safe name spaces!)</li>
<li><a href="./Documentation/Arguments.md">Argument Passing</a> (Resolver 1.2 now has built in support for multiple arguments!)</li>
<li><a href="./Documentation/Containers.md">Custom Containers &amp; Nested Containers</a></li>
<li><a href="./Documentation/CyclicDependencies.md">Cyclic Dependency Support</a></li>
<li><a href="./Documentation/Storyboards.md">Storyboard Support</a></li>
</ul>

<p>TLDR: If nothing else, make sure you read about <a href="./Documentation/Types.md">Automatic Type Inference</a>, <a href="./Documentation/Scopes.md">Scopes</a>, and <a href="./Documentation/Optionals.md">Optionals</a>.</p>
<h2 id='using-resolver' class='heading'>Using Resolver</h2>

<p>Using Resolver is a simple, three-step process:</p>

<ol>
<li><a href="./Documentation/Installation.md">Add Resolver to your project.</a></li>
<li><a href="./Documentation/Registration.md">Register the classes and services your app requires.</a></li>
<li><a href="./Documentation/Resolving.md">Use Resolver to resolve those instances when needed.</a></li>
</ol>
<h2 id='installation' class='heading'>Installation</h2>

<p>Resolver supports CocoaPods and the Swift Package Manager.</p>
<pre class="highlight swift"><code><span class="n">pod</span> <span class="s">"Resolver"</span>
</code></pre>

<p>Resolver itself is just a single source file (Resolver.swift), so it&rsquo;s also easy to simply download the file and add it to your project.</p>

<p>Note that the current version of Resolver (1.1) supports Swift 5.1 and that the minimum version of iOS currently supported with this release is iOS 11.</p>

<p>Read the <a href="./Documentation/Installation.md">installation guide</a> for information on supporting earlier versions.</p>
<h2 id='why-resolver' class='heading'>Why Resolver?</h2>

<p>As mentioned, Resolver is an ultralight Dependency Injection system, implemented in just over 700 lines of code and contained in a single file.</p>

<p>Resolver is also designed for performance. <a href="https://github.com/Swinject/SwinjectStoryboard">SwinjectStoryboard</a>, for example, is a great dependency injection system, but Resolver clocks out to be about 800% faster at resolving dependency chains than Swinject.</p>

<p>And unlike some other systems, Resolver is written in 100% Swift 5, with no Objective-C code, method swizzling, or internal dependencies on the Objective-C runtime.</p>

<p>Further, Resolver:</p>

<ul>
<li>Is tested in production code.</li>
<li><a href="./Documentation/Threads.md">Is thread safe (assuming your objects are thread safe).</a> (Updated in 1.4.)</li>
<li>Has a complete set of unit tests.</li>
<li>Is well-documented.</li>
</ul>

<p>Finally, with  <a href="./Documentation/Types.md">Automatic Type Inference</a> you also tend to write about 40-60% less dependency injection code using Resolver.</p>
<h2 id='author' class='heading'>Author</h2>

<p>Resolver was designed, implemented, and documented by <a href="https://www.linkedin.com/in/hmlong/">Michael Long</a>, a Senior Lead iOS engineer at <a href="https://www.clientresourcesinc.com/solutions/">CRi Solutions</a>. CRi is a leader in developing cutting edge iOS, Android, and mobile web applications and solutions for our corporate and financial clients.</p>

<ul>
<li>Email: <a href="mailto:mlong@clientresourcesinc.com">mlong@clientresourcesinc.com</a></li>
<li>Twitter: @hmlco</li>
</ul>
<h2 id='license' class='heading'>License</h2>

<p>Resolver is available under the MIT license. See the LICENSE file for more info.</p>
<h2 id='additional-resouces' class='heading'>Additional Resouces</h2>

<ul>
<li><a href="./Documentation/API/Classes/Resolver.html">API Documentation</a></li>
<li><a href="https://en.wikipedia.org/wiki/Inversion_of_control">Inversion of Control Design Pattern ~ Wikipedia</a></li>
<li><a href="https://martinfowler.com/articles/injection.html">Inversion of Control Containers and the Dependency Injection pattern ~ Martin Fowler</a></li>
<li><a href="https://cocoacasts.com/nuts-and-bolts-of-dependency-injection-in-swift/">Nuts and Bolts of Dependency Injection in Swift</a>\</li>
<li><a href="https://cocoacasts.com/dependency-injection-in-swift">Dependency Injection in Swift</a></li>
<li><a href="https://github.com/Swinject/SwinjectStoryboard">SwinjectStoryboard</a></li>
<li><a href="https://medium.com/better-programming/taking-swift-dependency-injection-to-the-next-level-b71114c6a9c6">Swift 5.1 Takes Dependency Injection to the Next Level</a></li>
</ul>

          </section>
        </section>
        <section id="footer">
          <p>&copy; 2021 <a class="link" href="https://github.com/hmlongco/Resolver" target="_blank" rel="external">Michael Long</a>. All rights reserved. (Last updated: 2021-01-09)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
